<?php
class c_areas extends DtDatabase
{
	public $area_id;
	public $parent_id;
	public $area_name;
	public $py_name;
	public $zipcode;
	public $area_type;
	public $special;

	public $primary_key='id';

	protected $table_name;
	private $im_virgin=false;

	public function __construct()
	{
		$this->table_name = TB_PREFIX.'areas';
		$this->DtDatabase();		
}
	public function get_request($request=array())
	{
		if(!empty($request)){
		if($request['area_id'])$this->area_id=$request['area_id'];
		if($request['parent_id'])$this->parent_id=$request['parent_id'];
		if($request['area_name'])$this->area_name=$request['area_name'];
		if($request['py_name'])$this->py_name=$request['py_name'];
		if($request['zipcode'])$this->zipcode=$request['zipcode'];
		if($request['area_type'])$this->area_type=$request['area_type'];
		if($request['special'])$this->special=$request['special'];
		}
		}

	public function addnew($request=array())
	{
		$this->im_virgin =true;		if(!empty($request)){
		$this->get_request($request);
		}
		}

	public function save()
	{
		if($this->im_virgin){
		eval("\$this->$this->primary_key=NULL;");
		$sql="INSERT INTO `$this->table_name` (";
		$sql.=isset($this->area_id)?"area_id,":'';
		$sql.=isset($this->parent_id)?"parent_id,":'';
		$sql.=isset($this->area_name)?"area_name,":'';
		$sql.=isset($this->py_name)?"py_name,":'';
		$sql.=isset($this->zipcode)?"zipcode,":'';
		$sql.=isset($this->area_type)?"area_type,":'';
		$sql.=isset($this->special)?"special,":'';
if(substr($sql,strlen($str)-1,1)==',')$sql=substr($sql,0,strlen($str)-1);		$sql.=")VALUES (";
		$sql.=isset($this->area_id)?"'$this->area_id',":'';
		$sql.=isset($this->parent_id)?"'$this->parent_id',":'';
		$sql.=isset($this->area_name)?"'$this->area_name',":'';
		$sql.=isset($this->py_name)?"'$this->py_name',":'';
		$sql.=isset($this->zipcode)?"'$this->zipcode',":'';
		$sql.=isset($this->area_type)?"'$this->area_type',":'';
		$sql.=isset($this->special)?"'$this->special',":'';
if(substr($sql,strlen($str)-1,1)==',')$sql=substr($sql,0,strlen($str)-1);		$sql.=')';

		}
		else{

		eval('$pid=$this->'.$this->primary_key.';$this->'.$this->primary_key.'=NULL;');

		$sql.="UPDATE `$this->table_name` SET ";
		$sql.=isset($this->area_id)?"`area_id`='$this->area_id',":'';
		$sql.=isset($this->parent_id)?"`parent_id`='$this->parent_id',":'';
		$sql.=isset($this->area_name)?"`area_name`='$this->area_name',":'';
		$sql.=isset($this->py_name)?"`py_name`='$this->py_name',":'';
		$sql.=isset($this->zipcode)?"`zipcode`='$this->zipcode',":'';
		$sql.=isset($this->area_type)?"`area_type`='$this->area_type',":'';
		$sql.=isset($this->special)?"`special`='$this->special',":'';
if(substr($sql,strlen($str)-1,1)==',')$sql=substr($sql,0,strlen($str)-1);
		$sql.=" WHERE `$this->primary_key` ='$pid' LIMIT 1";
		}
		return $this->query($sql);
	}
}
?>